<template>
	<view class="content_view">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" title="火情报警描述"></u-navbar>
		<uc-content :loading="loading">
			<u-form ref="fireForm" :model="fireForm" label-width="100px" class="wrap">
				<u-form-item label="区域名称" prop="regionName">
					<u-input type="select" :select-open="regionShow" placeholder="请选择区域" v-model="fireForm.regionName"
						@click="regionShow=true"></u-input>
				</u-form-item>
				<u-form-item label-position="left" label="火情地址" prop="loaction">
					<u-input type="text" placeholder="如二楼肯德基店发生火情" v-model="fireForm.location" />
				</u-form-item>
				<u-form-item label="模式" prop="type" v-if="regionInfo.drill">
					<u-radio-group v-model="fireForm.type" @change="radioGroupChange">
						<u-radio v-for="(item,index) in typeList" :key="index" :name="item.value">{{item.label}}</u-radio>
					</u-radio-group>
				</u-form-item>
				<view class="u-m-t-20 u-text-center" v-if="regionInfo.drill">
					当前区域已被标识演练区域，如需报火警请选择报警模式
				</view>
			</u-form>
			<u-select :default-value="defaultValue" mode="mutil-column-auto" :list="regionList" value-name="ucId"
				label-name="name" v-model="regionShow" @confirm="regionConfirm"></u-select>
			<u-button @click="submit" type="error" style="margin: 24rpx;">确定火情</u-button>
		</uc-content>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fireForm: {
					regionId: '',
					location: '',
					type:0,
				},
				loading:false,
				regionInfo: {},
				typeList: [
					{
						value:1,
						label: '演练'
					},
					{
						value:0,
						label: '火情'
					}
				],
				regionShow: false,
				regionList: [],
				defaultValue: [0,0],
				rules: {
					regionName: [{
						required: true,
						message: '请选择区域',
						trigger: ['change', 'blur'],
					}],
					type:[{
						required: true,
						message: '请选择模式',
						trigger: ['change', 'blur'],
					}]
				},
			}
		},
		onLoad(e) {
			console.log(e.ucId)
			this.fireForm.ucId = e.ucId
		},
		onShow() {
			this.initView()
		},
		onReady(e) {
			this.$refs.fireForm.setRules(this.rules)
		},
		methods: {
			initView() {
				this.loading = true
				this.getInRegionList()
			},
			getInRegionList() {
				this.utils.request("/api/app/region/getSubfieldRegionList", {currentHandle:true}, "post", "app", true).then(res => {
					this.regionList = res.data
					this.regionInfo=res.data[0].children[0]
					this.fireForm.regionId=this.regionInfo.ucId
					this.fireForm.regionName=this.regionInfo.name
					this.loading = false
				}).catch(error => {
					this.loading = false
					console.log(error)
				})
			},
			getInRegionVo() {
				uni.showLoading({
				    title: '加载中'
				});
				this.utils.request("/api/app/region/getInRegionVo", {ucId: this.fireForm.regionId}, "post", "app", true).then(res => {
					this.regionInfo = res.data
					if(res.data.drill){
						this.fireForm.type=1
					}
					uni.hideLoading();
				}).catch(error => {
					uni.hideLoading();
					console.log(error)
				})
			},
			regionConfirm(e) {
				e.map((val, index) => {
					this.fireForm.regionName = val.label
					this.fireForm.regionId = val.value
					this.getInRegionVo()
				})
			},
			radioGroupChange(e) {
				console.log(e)
			},
			submit() {
				this.$refs.fireForm.validate(valid => {
					if (valid) {
						this.utils.request("/api/app/inAlarmRecord/confirmFire", this.fireForm,
							"post", "app", true).then(res => {
							uni.navigateTo({
								url:"/pages/index/abnormal/returnedSuccessfully?noticeId=" + res.data.noticeId + "&fireInfoId=" + res.data.fireInfoId + "&audioId=1&mark=1"
							})
						}).catch(error => {
							console.log(error)
						})
					} else {
						console.log("验证失败")
					}
				})
			},

		}
	}
</script>

<style>

</style>
